package com.ophiux.cs.api.chat.impl;

import java.lang.reflect.Type;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.gson.reflect.TypeToken;
import com.ophiux.cs.api.chat.port.ICSUserApiPort;
import com.ophiux.cs.application.consult.dto.CSConInitRequest;
import com.ophiux.cs.application.consult.service.ICSConInitAppService;
import com.ophiux.cs.application.core.AppResultCode;
import com.ophiux.cs.application.core.Request;
import com.ophiux.cs.application.core.Result;
import com.ophiux.utils.parser.json.JsonUtils;
import com.ophiux.utils.parser.json.JsonUtils.TypeObtainCallback;

import lombok.extern.slf4j.Slf4j;

/**
 * 咨询用户api
 * @author chenh
 *
 */
@Service("cSUserApiService")
@Slf4j
public class CSUserApiService implements ICSUserApiPort{

	@Autowired
	ICSConInitAppService cSConInitAppService;
	
	@Override
	public String CSInit(String data) {
		log.info("CSInit接口,请求参数："+data);
		Result result = null;
		Request<CSConInitRequest> request = null;
		try {
			request = JsonUtils.toEntity(data, new TypeObtainCallback() {
				public Type getObtainType() {
					return new TypeToken<Request<CSConInitRequest>>() {
					}.getType();
				}
			});
			
			result = cSConInitAppService.ConInit(request.getPARAM());
			
		} catch (Exception e) {
			log.info("ApplayCSPublish接口异常：",e);
			e.printStackTrace();
			result = Result.fail(AppResultCode.EXCEPTION, e.getMessage());
			return JsonUtils.toJson(result);
		}
			
		String returnMessage = JsonUtils.toJson(result);
		log.info("ApplayCSPublish接口,返回参数："+returnMessage);
		return returnMessage;
	}

	
	@Override
	public String GetCSTargetID(String data) {
		// TODO Auto-generated method stub
		return null;
	}
	
}
